package com.example.forumsystem.controller;

import com.example.forumsystem.common.AppResult;
import com.example.forumsystem.dao.UserMapper;
import com.example.forumsystem.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "测试类相关接口")

@RequestMapping("/text")
@RestController
@Slf4j
public class TextController {
    @Autowired
    UserMapper userMapper;

    @ApiOperation("你好SpringBoot")
    @GetMapping("/hello")
    public String hello() {
        return "hello SpringBoot...";
    }
    /**
     * 统一异常测试
     */
    @ApiOperation("Exception测试")
    @GetMapping("/excaption")
    public void textExcaption() throws Exception {
        throw new Exception("这是一个 Exception.....");
    }
    @ApiOperation("ApplicationException测试")

    @GetMapping("/appExcaption")
    public void textApplicationExcaption() {
        throw new ApplicationException("这是一个 ApplicationException...");

    }

    @ApiOperation("获取姓名")
    @PostMapping("getUserName")
    public AppResult getUserName(@ApiParam("用户名") @RequestParam("userName") String userName) {
        return AppResult.success(userName);
    }
}
